import Vue from 'vue'
import MyVuex from '../my-vuex/index.js'
import myPlugin from './myPlugin'
Vue.use(MyVuex)

const store = new MyVuex.Store({
    state: {
        count: 0
    },
    mutations: {
        increment(state, payload) {
            state.count += payload || 1
        }
    },
    actions: {
        asyncIncrement({ commit }, payload) {
            setTimeout(() => {
                commit('increment', payload)
            }, 1000)
        }
    },
    getters: {
        doubleCount(state) {
            return state.count * 2
        }
    },
    plugins: [myPlugin({
        key: 'vuex-state',
        storage: localStorage,
        paths: ['count']
    })],
    strict: false,
    modules: {
        user: {
            state: { name: 'Tom' },
            mutations: {
                setName(state, name) {
                    state.name = name
                }
            },
            actions: {
                login({ commit }) {
                    commit('setName', 'New Name')
                },
                loginw({ commit }) {
                    commit('setName', 'New Name')
                }
            }
        },
        // counter: {
        //     state: { count: 0 },
        //     mutations: {
        //         increment(state) {
        //             state.count++
        //         }
        //     },
        //     modules: {
        //         user: {
        //             state: { name: 'Tom' },
        //             mutations: {
        //                 setName(state, name) {
        //                     state.name = name
        //                 }
        //             },
        //             actions: {
        //                 login({ commit }) {
        //                     commit('setName', 'New Name')
        //                 },
        //                 loginw({ commit }) {
        //                     commit('setName', 'New Name')
        //                 }
        //             }
        //         }
        //     }
        // }
    }
})
console.log('store', store)
export default store